<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="shortcut icon" href="../../../favicon.ico" type="image/x-icon">
	<title>highOrderComponent</title>
</head>
<body>
  <div id="test"></div>

  <script type="text/javascript" src="../../../js/react.development.js" ></script>
  <script type="text/javascript" src="../../../js/react-dom.development.js"></script>
  <script type="text/javascript" src="../../../js/babel.min.js"></script>
  <script type="text/javascript" src="../../../js/prop-types.js"></script>

  <script type="text/babel">
    class Login extends React.Component {
      state={
        username:'',
        password:''
      }

      onSubmit=(event)=>{
        event.preventDefault(); // 阻止表单提交
        const {username, password} = this.state;
        console.log('username:'+username+' password:'+password)
      }

      /**
       * 高阶函数:入参或出参是一个函数的函数,即为高阶函数
       * 函数的柯里化:通过函数调用继续返回一个函数的方式,实现多次接收参数并在最后统一处理的编码方式
       * 下列方法即为高阶函数,也是柯里化的函数
       */
      saveData=(dataType)=>{
        return (event)=>{
          this.setState({
            [dataType]: event.target.value
          })
        }
      }

      render(){
        return (
          <form onSubmit={this.onSubmit}>
            username: <input onChange={this.saveData('username')} type="text" name="username" />
            password: <input onChange={this.saveData('password')} type="password" name="password" />
            <button>login</button>
          </form>
        )
      }
    }

    ReactDOM.render(<Login />, document.getElementById('test'));
  </script>
</body>